<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    //父类
    function People(name, age) {
        this.name = name || 'wangxiao'
        this.age = age || 27
    }

    //父类方法
    People.prototype.eat = function () {
        return this.name + this.age + 'eat sleep'
    }

    //子类
    function Woman(name, age) {
        //继承父类属性（使用 call 将 people 中的 this 替换为了 new Woman()）
        People.call(this, name, age)
    }

    //继承父类方法
    (function () {
        // 创建空类
        let Super = function () {
        };
        Super.prototype = People.prototype;
        //父类的实例作为子类的原型
        Woman.prototype = new Super();
    })();
    //修复构造函数指向问题
    Woman.prototype.constructor = Woman;
    let womanObj = new Woman();
    console.log(womanObj);
</script>
</body>
</html>
